package com.leased.service.impl;

import com.leased.exception.DatabaseException;
import com.leased.interceptor.PageMybatisInterceptor;
import com.leased.mapper.manual.ICustomizedItemMapper;
import com.leased.request.item.ThatDayItemRequest;
import com.leased.response.ThatDayItemResponse;
import com.leased.service.ItemService;
import com.leased.utils.Page;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;

/**
 * Created by shencx on 2017/8/3.
 */
@Service
public class ItemServiceImpl implements ItemService{

    Logger LOG = LoggerFactory.getLogger(ItemServiceImpl.class);

    @Resource
    private ICustomizedItemMapper customizedItemMapper;

    /**
     * 获取当日发布信息列表
     * @param thatDayItemRequest
     * @return
     * @throws DatabaseException
     */
    @Override
    public Page<ThatDayItemResponse> fetchThatDayItemPage(ThatDayItemRequest thatDayItemRequest) throws DatabaseException {
        try {
            if (thatDayItemRequest == null){
                LOG.error("fetchThatDayItemPage  信息为空",thatDayItemRequest);
                return null;
            }
            PageMybatisInterceptor.startPage(thatDayItemRequest.getPageNum(),thatDayItemRequest.getPageSize());
            customizedItemMapper.findThatDayItemList(thatDayItemRequest);
            Page<ThatDayItemResponse> page = PageMybatisInterceptor.endPage();
            return page;
        } catch (Throwable e) {
            LOG.error("fetchThatDayItemPage 发生异常",e,thatDayItemRequest);
            throw new DatabaseException(e.getMessage());
        }
    }
}
